Apex-এ Arithmetic এবং Logical Operators প্রোগ্রামে গণিত এবং লজিক্যাল অপারেশন সম্পাদনের জন্য ব্যবহৃত হয়। এসব অপারেটর ডেটার উপর বিভিন্ন ধরণের গণনা ও তুলনা সম্পন্ন করে। নিচে Apex-এ ব্যবহৃত Arithmetic এবং Logical Operators এর বিস্তারিত ব্যাখ্যা করা হলো।
Arithmetic Operators মূলত গণিত সম্পর্কিত অপারেশন করতে ব্যবহৃত হয়। এগুলোর মাধ্যমে যোগ, বিয়োগ, গুণ, ভাগ এবং মডুলাস অপারেশন করা যায়।
অপারেটর | বর্ণনা | উদাহরণ |
---|---|---|
+ | যোগ | a + b |
- | বিয়োগ | a - b |
* | গুণ | a * b |
/ | ভাগ | a / b |
% | মডুলাস (বাকি) | a % b |
Integer a = 10;
Integer b = 3;
Integer sum = a + b; // যোগফল: 13
Integer difference = a - b; // বিয়োগফল: 7
Integer product = a * b; // গুণফল: 30
Integer quotient = a / b; // ভাগফল: 3
Integer remainder = a % b; // মডুলাস: 1
System.debug('Sum: ' + sum);
System.debug('Difference: ' + difference);
System.debug('Product: ' + product);
System.debug('Quotient: ' + quotient);
System.debug('Remainder: ' + remainder);
Logical Operators মূলত লজিক্যাল অপারেশন সম্পন্ন করতে ব্যবহৃত হয়, যেখানে এক বা একাধিক শর্ত মিলে একটি চূড়ান্ত ফলাফল দেয়। Apex-এ তিনটি প্রধান Logical Operators রয়েছে: AND, OR, এবং NOT।
অপারেটর | নাম | বর্ণনা | উদাহরণ |
---|---|---|---|
&& | Logical AND | দুইটি শর্ত সত্য হলে পুরো অপারেশন সত্য হবে। | (a > b) && (a > c) |
` | ` | Logical OR | |
! | Logical NOT | শর্তের বিপরীত মান প্রদান করে; সত্যকে মিথ্যা এবং মিথ্যাকে সত্যে পরিবর্তন করে। | !(a > b) |
Boolean x = true;
Boolean y = false;
// Logical AND
Boolean resultAnd = x && y; // false, কারণ একটি শর্ত মিথ্যা
// Logical OR
Boolean resultOr = x || y; // true, কারণ একটি শর্ত সত্য
// Logical NOT
Boolean resultNot = !x; // false, কারণ x সত্য ছিল
System.debug('Logical AND: ' + resultAnd);
System.debug('Logical OR: ' + resultOr);
System.debug('Logical NOT: ' + resultNot);
নিচের উদাহরণে, Arithmetic এবং Logical Operators ব্যবহার করে শর্তের ভিত্তিতে গণনা করা হয়েছে:
public class OperatorExample {
public void calculate(Integer a, Integer b) {
// Arithmetic Operations
Integer sum = a + b;
Integer difference = a - b;
Integer product = a * b;
Integer quotient = a / b;
Integer remainder = a % b;
System.debug('Sum: ' + sum);
System.debug('Difference: ' + difference);
System.debug('Product: ' + product);
System.debug('Quotient: ' + quotient);
System.debug('Remainder: ' + remainder);
// Logical Operations
Boolean isSumPositive = sum > 0;
Boolean isDifferenceNegative = difference < 0;
if (isSumPositive && !isDifferenceNegative) {
System.debug('Sum is positive and difference is not negative.');
} else if (isSumPositive || isDifferenceNegative) {
System.debug('Either sum is positive or difference is negative.');
} else {
System.debug('Neither sum is positive nor difference is negative.');
}
}
}
Apex প্রোগ্রামিং এ Arithmetic এবং Logical Operators ব্যবহার করে বিভিন্ন ধরণের গণিত ও লজিক্যাল অপারেশন সম্পন্ন করা সহজ হয়, যা ডেটা ম্যানিপুলেশন এবং শর্ত নির্ধারণে গুরুত্বপূর্ণ ভূমিকা পালন করে।
common.read_more